# PowerShell 脚本：配置 Electron 和 Electron Builder 环境变量
Write-Host "正在配置 Electron 和 Electron Builder 镜像环境变量..." -ForegroundColor Green

# 设置 Electron 环境变量
$env:ELECTRON_MIRROR = "https://npmmirror.com/mirrors/electron/"
$env:ELECTRON_CACHE = "$env:USERPROFILE\.electron-cache"

# 设置 Electron Builder 环境变量
$env:ELECTRON_BUILDER_BINARIES_MIRROR = "https://ghproxy.com/https://github.com/electron-userland/electron-builder-binaries/releases/download/"
$env:ELECTRON_BUILDER_CACHE = "$env:USERPROFILE\.electron-builder-cache"

# 显示当前配置
Write-Host ""
Write-Host "当前配置:" -ForegroundColor Yellow
Write-Host "ELECTRON_MIRROR = $env:ELECTRON_MIRROR" -ForegroundColor Cyan
Write-Host "ELECTRON_CACHE = $env:ELECTRON_CACHE" -ForegroundColor Cyan
Write-Host "ELECTRON_BUILDER_BINARIES_MIRROR = $env:ELECTRON_BUILDER_BINARIES_MIRROR" -ForegroundColor Cyan
Write-Host "ELECTRON_BUILDER_CACHE = $env:ELECTRON_BUILDER_CACHE" -ForegroundColor Cyan

# 创建缓存目录
$cacheDirs = @($env:ELECTRON_CACHE, $env:ELECTRON_BUILDER_CACHE)
foreach ($dir in $cacheDirs) {
    if (!(Test-Path $dir)) {
        New-Item -ItemType Directory -Path $dir -Force | Out-Null
        Write-Host "已创建缓存目录: $dir" -ForegroundColor Green
    }
}

Write-Host ""
Write-Host "环境变量配置完成！" -ForegroundColor Green
Write-Host "现在可以运行以下命令进行构建:" -ForegroundColor Yellow
Write-Host "  pnpm run electron:build" -ForegroundColor Cyan
Write-Host ""
Write-Host "如果仍然遇到下载问题，可以尝试:" -ForegroundColor Yellow
Write-Host "  pnpm run electron:build:no-sign" -ForegroundColor Cyan